<template>
    <div>
        <h1>新增机构</h1>

        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td align="right">机构名称</td>
                    <td><input type="text" v-model="queryInfo.name"></td>
                </tr>

                <tr>
                    <td align="right">机构封面</td>
                    <td>
                        <input type="file" @change="getphoto">
                        <img :src="queryInfo.photo" width="100" height="100" alt="">
                    </td>
                </tr>

                <tr>
                    <td align="right">特色服务</td>
                    <td>
                        <select v-model="queryInfo.conManyFwid">
                            <option value="0">请选择</option>
                            <option :value="1">24h监护</option>
                            <option :value="2">特殊护理</option>
                        </select>
                    </td>
                </tr>

                <tr>
                    <td align="right">营业时间</td>
                    <td>
                        <input type="date" v-model="queryInfo.yyTime">
                    </td>
                </tr>

                <tr>
                    <td align="right">机构地址</td>
                    <td>
                        <input type="text" v-model="queryInfo.adress">
                    </td>
                </tr>

                <tr>
                    <td align="right">联系电话</td>
                    <td>
                        <input type="text" v-model="queryInfo.phone">
                    </td>
                </tr>

                <tr>
                    <td align="right">发布时间</td>
                    <td>
                        <input type="radio" name="time" :value="1" v-model="queryInfo.state">立即发布
                        <input type="radio" name="time" :value="0" v-model="queryInfo.state">暂不发布
                    </td>
                </tr>

                <tr>
                    <td align="right">机构详情</td>
                    <td>
                        <textarea cols="60" rows="6" v-model="queryInfo.des">

                        </textarea>
                    </td>
                </tr>


                <tr>
                    <td align="right"></td>
                    <td>
                        <input type="button" value="添加" class="btn btn-primary" @click="ok">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted} from 'vue'
import { useRoute, useRouter } from 'vue-router'
import axios from 'axios';
const router = useRouter()
const route = useRoute()


let queryInfo = reactive({
  name: '',
  photo: '',
  conManyFwid: 0,
  yyTime: '',
  adress: '',
  phone: '',
  state: 1,
  des: '',
})


const getphoto = (e:any) => {
    let file = e.target.files[0]
    let formdata = new FormData()
    formdata.append('file',file)
    axios
    .post('/api/Conner/GetPhoto',formdata)
    .then((res)=>{
        console.log(res)
        alert('上传成功');
        queryInfo.photo = res.data;
    })
    .catch((err)=>{
        console.log(err)
    })
}


const ok = () => {
    if(queryInfo.name == ''){
        alert('机构名称不能为空');
        return;
    }
    if(queryInfo.photo == ''){
        alert('机构封面不能为空');
        return;
    }
    if(queryInfo.conManyFwid == 0){
        alert('特色服务不能不选');
        return;
    }
    if(queryInfo.adress == ''){
        alert('机构地址不能为空');
        return;
    }
    if(queryInfo.phone == ''){
        alert('联系电话不能为空');
        return;
    }

    axios({
        url:'/api/ConMany/Add',
        method:'post',
        data:queryInfo
    })
    .then((res)=>{
        console.log(res)
        if(res.data >0)
        {
            alert('添加成功')
            router.push('/conmanylist')
        }
    })
    .catch((err)=>{
        console.log(err)
    })
}



</script>

<style scoped>
h1{
    text-align: center;
    color: royalblue;
}
</style>